package com.college.controller.products;


import com.college.common.pojo.ao.ProductsType;
import com.college.common.pojo.dto.products.AddProductsTypeDTO;
import com.college.common.pojo.dto.products.QueryProductsTypeDTO;
import com.college.common.pojo.dto.products.UpdateProductsTypeDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonPage;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.products.service.ProductsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品分类 前端控制器
 * @author 小C工作室
 * @since 2025-02-22
 */
@RestController
@RequestMapping("/products-type")
@Api(tags = "商品分类")
@Slf4j
public class ProductsTypeController {

    @Autowired
    private ProductsTypeService productsTypeService;

    @ApiOperation(value = "查询商品分类列表")
    @GetMapping(value = "/query-list")
    public CommonResult<List<ProductsType>> queryList(QueryProductsTypeDTO queryProductsTypeDTO) {
        return CommonResult.success(productsTypeService.queryList(queryProductsTypeDTO));
    }

    @ApiOperation(value = "查询商品分类列表分页")
    @GetMapping(value = "/query-list-page")
    public CommonResult<CommonPage<ProductsType>> queryListPage(QueryProductsTypeDTO queryProductsTypeDTO , PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(productsTypeService.queryListPage(queryProductsTypeDTO,pageParamRequest)));
    }

    @ApiOperation(value = "新增商品分类")
    @PostMapping(value = "/add")
    public CommonResult<String> addProductsType(@RequestBody AddProductsTypeDTO addProductsTypeDTO) {
        return productsTypeService.addProductsType(addProductsTypeDTO);
    }

    @ApiOperation(value = "删除商品分类")
    @DeleteMapping(value = "/delete/{id}")
    public CommonResult<Boolean> deleteProductsType(@PathVariable Long id) {
        return CommonResult.success(productsTypeService.removeById(id));
    }

    @ApiOperation(value = "批量删除商品分类")
    @DeleteMapping(value = "/batch-delete")
    public CommonResult<Boolean> deleteProductsType(@RequestBody List<Long> ids) {
        if (ObjectUtil.isNotEmpty(ids)) {
            return CommonResult.success(productsTypeService.removeByIds(ids));
        }
        return CommonResult.success("参数错误");
    }

    @ApiOperation(value = "更新商品分类")
    @PutMapping(value = "/update")
    public CommonResult<String> updateProductsType(@RequestBody UpdateProductsTypeDTO updateProductsTypeDTO) {
        return productsTypeService.updateProductsType(updateProductsTypeDTO);
    }
}

